package com.nmsl.sn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.sn.domain.SnFamilyMember;
import com.nmsl.sn.service.ISnFamilyMemberService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 家属Controller
 * 
 * @author ruoyi
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/sn/member")
public class SnFamilyMemberController extends BaseController
{
    @Autowired
    private ISnFamilyMemberService snFamilyMemberService;

    /**
     * 查询家属列表
     */
    @PreAuthorize("@ss.hasPermi('sn:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnFamilyMember snFamilyMember)
    {
        startPage();
        List<SnFamilyMember> list = snFamilyMemberService.selectSnFamilyMemberList(snFamilyMember);
        return getDataTable(list);
    }

    /**
     * 导出家属列表
     */
    @PreAuthorize("@ss.hasPermi('sn:member:export')")
    @Log(title = "家属", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnFamilyMember snFamilyMember)
    {
        List<SnFamilyMember> list = snFamilyMemberService.selectSnFamilyMemberList(snFamilyMember);
        ExcelUtil<SnFamilyMember> util = new ExcelUtil<SnFamilyMember>(SnFamilyMember.class);
        util.exportExcel(response, list, "家属数据");
    }

    /**
     * 获取家属详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:member:query')")
    @GetMapping(value = "/{familyMemberId}")
    public AjaxResult getInfo(@PathVariable("familyMemberId") Long familyMemberId)
    {
        return success(snFamilyMemberService.selectSnFamilyMemberByFamilyMemberId(familyMemberId));
    }

    /**
     * 新增家属
     */
    @PreAuthorize("@ss.hasPermi('sn:member:add')")
    @Log(title = "家属", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnFamilyMember snFamilyMember)
    {
        return toAjax(snFamilyMemberService.insertSnFamilyMember(snFamilyMember));
    }

    /**
     * 修改家属
     */
    @PreAuthorize("@ss.hasPermi('sn:member:edit')")
    @Log(title = "家属", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnFamilyMember snFamilyMember)
    {
        return toAjax(snFamilyMemberService.updateSnFamilyMember(snFamilyMember));
    }

    /**
     * 删除家属
     */
    @PreAuthorize("@ss.hasPermi('sn:member:remove')")
    @Log(title = "家属", businessType = BusinessType.DELETE)
	@DeleteMapping("/{familyMemberIds}")
    public AjaxResult remove(@PathVariable Long[] familyMemberIds)
    {
        return toAjax(snFamilyMemberService.deleteSnFamilyMemberByFamilyMemberIds(familyMemberIds));
    }
    /**
     * 根据患者id查找家属
     */

    @GetMapping("/list/{patientId}")
    public List<SnFamilyMember> selectSnFamilyMemberByPatientId(@PathVariable("patientId") Long patientId){
        return snFamilyMemberService.selectSnFamilyMemberByPatientId(patientId);
    }
}
